var accountManagement={
    init:function(){
        var self=this;
        self.shadeDiv = $("#shade-div");
        self.bindEvents();
        self.loadTree();
    },
    bindEvents:function(){
        var self=this;
//        新增账户输入用户名检验
        $("#validate input").blur(function(){
            //检验输入用户，配合后台
            var status=true;
            var $span=$(this).siblings("span")
            if(status){
                $span.addClass("suc").text("")
            }else{
                $span.removeClass("suc").text("用户输入错误，请重新输入")
            }
            $span.show();
        })
        $("#validate input").focus(function(){
            $(this).siblings("span").removeClass("suc").hide();
        })
//        新增账户
        $("#newAccount").click(function(){
            self.shadeDiv.show();
            $('#addAccount').setPosition().show();
        })
//        编辑账户
        $(".edit").click(function(){
            self.shadeDiv.show();
            $('#editAccount').setPosition().show();
        })
//        删除账户
        $(".del").click(function(){
            self.shadeDiv.show();
            $('#warning').setPosition().show().find("p.center").html("确定要删除此账户吗？");
        })
        $("#search").textClean()



    },
    loadTree:function(){
        $.fn.zTree.init($("#treeDemo"), setting, zNode1);
        $.fn.zTree.init($("#treeDemo1"), setting1, zNode2);
        $.fn.zTree.init($("#treeDemo2"), setting1, zNode1);
        $.fn.zTree.init($("#treeDemo3"), setting1, zNode2);
        $.fn.zTree.init($("#treeDemo4"), setting1, zNode1);
    },
    ajaxGET:function (url, data, fn,beforeSendFn) {
        var beforeSendFn = beforeSendFn || function(){};
        $.ajax({type:"GET", dataType:'json', context:this, url:url, data:data, success:fn, beforeSend:beforeSendFn});
    },
    ajaxPOST:function (url, data, fn,beforeSendFn) {
        var beforeSendFn = beforeSendFn || function(){};
        $.ajax({type:"POST", dataType:'json', context:this, url:url, data:data, success:fn, beforeSend:beforeSendFn});
    }
}
$(function(){
    accountManagement.init()
})